#pragma once
#include <WinSock2.h>
#include <boost/bind.hpp>
#include <boost/function.hpp>
namespace ms{
namespace http{
namespace server{
    class Session;

    class TcpAccept
    {
		TcpAccept();
    public:
        TcpAccept(unsigned short port);
        ~TcpAccept();
        typedef void HandleAccept(Session* session);


        BOOL Accept(Session* s, boost::function<void(Session*)>* );
        SOCKET GetSocket(){return _socket;}
		SOCKET _socket;

		BOOL Stop(long ms_time = 0);
		struct accept_state{
			enum value_t{realy, working, stoping, stop};
		};
		const accept_state::value_t& GetStatus()const{
			return _accept_state;
		}
    private:
		BOOL Init();
		unsigned short port_;
		struct socket_state{
			enum value_t{blocking, non_blocking };
		};
		socket_state::value_t _socket_model;

		accept_state::value_t _accept_state;
    };



}// server
} // http
} // mt